﻿using System;
using System.Windows.Forms;
using NonLeagueExplorer.Config;

namespace NonLeagueExplorer.Forms
{
    public partial class AddOrEditLeagueForm : Form
    {
        public LeagueData LeagueDetails
        {
            get;
            set;
        }

        public AddOrEditLeagueForm()
        {
            InitializeComponent();
        }

        public AddOrEditLeagueForm(LeagueData p_EditLeague) :
            this()
        {
            LeagueDetails = p_EditLeague;
            FillForm(p_EditLeague);
        }

        private void FillForm(LeagueData p_EditLeague)
        {
            LeagueName.Text = p_EditLeague.Name;
            Step.Text = p_EditLeague.Step.ToString();
            Fixtures.Text = p_EditLeague.FixturesURL;
            Results.Text = p_EditLeague.ResultsURL;
            League.Text = p_EditLeague.LeagueTableURL;
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            LeagueDetails.Name = LeagueName.Text;
            LeagueDetails.FixturesURL = Fixtures.Text;
            LeagueDetails.ResultsURL = Results.Text;
            LeagueDetails.LeagueTableURL = League.Text;

            int dummy;
            int.TryParse(Step.Text, out dummy);
            LeagueDetails.Step = dummy;

            this.DialogResult = DialogResult.OK;
        }

        private void CancelBtn_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
